package com.yt.app.api.action;

import com.yt.app.api.action.base.BaseAction;
import com.yt.app.core.interfaces.StudentService;
import com.yt.app.core.model.Student;
import com.yt.core.MsgBean;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Api(tags = "04.学生")
@RequestMapping("/student")
public class StudentController extends BaseAction {
    @Autowired
    private StudentService studentService;
//    @ApiOperation(value="学生列表", httpMethod = "GET")
//    @ApiResponses(value = {@ApiResponse(code = 200,message = "学生属性", response = Student.class)})
    @RequestMapping("/list")
    public @ResponseBody Object studentList(@ApiParam("上次最后一个ID,传递接口json中返回的lastId") @RequestParam(value = "lastId", required = false, defaultValue = "0") Long lastId){
        MsgBean msgBean = new MsgBean();
        QueryFilter filter = new DynamicSQLFilterImpl();
        filter.addFilter("Q_status_N_EQ", "0");
        if(lastId > 0){
            filter.addFilter("Q_id_L_LT", String.valueOf(lastId));
        }
        filter.setSortField("id", true);
        List<Student> studentList = studentService.find(filter);

        if(studentList != null && !studentList.isEmpty()){
            msgBean.put("lastId", studentList.get(studentList.size()-1).getId());
        }else{
            msgBean.put("lastId", -1);
        }

        msgBean.put("activities", studentList);

        return msgBean.returnMsg();
    }
}
